home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-26 | 1.3 KB | 74 lines | [TEXT/ScoM] |
- >i was wondering how to use scom functions with delayed evaluation arguments.
- >that is, instead of the argument being evaluated, and then passed as a
- >parameter to the function, i want the function to take the argument as a
- >function, and evaluate it during the function's evaluation. does this make
- >sense?
-
- You can make it a macro and evaluate the parameter with eval. Here you
- supply the function call (rnd2 0 1) to the delayed-evaluation which
- then evaluates and prints the result 10 times. Notice that since this
- is a macro it will return a value which will be evaluated, since
- macros are usually used for making new Lisp forms which expand and
- evaluate. To overcome this make your macro returning nil.
-
- (defmacro delayed-evaluation (function)
- (dotimes (i 10)
- (print (eval function)))
- nil)
-
- (delayed-evaluation (rnd2 0 1))
-
- 0.7697816208819859
- 0.915418354110443
- 0.8008900594140869
- 0.9490920328971697
- 0.5024546815548092
- 0.7643523601145716
- 0.8911941803817172
- 0.7534653782931855
- 0.49140359536977485
- 0.33869340586534236
- nil
- ?
-
- If you want to evaluate any number of arguments in a similar way
- then make it this way.
-
- (defmacro delayed-evaluation2 (&rest body)
- (dotimes (i 10)
- (eval `(progn ,@body)))
- nil)
-
- (delayed-evaluation2 (print 1) (print 2) (print 3))
-
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
- 1
- 2
- 3
-